<?php
// +----------------------------------------------------------------------
// | MubinAdmin
// +----------------------------------------------------------------------
// | 版权所有 2015~2020 泉州市牧滨电子商务有限公司 [ http://www.mubin.com ]
// +----------------------------------------------------------------------
// | 官方网站: http://www.mubin.com
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 代码仓库：https://gitee.com/mubin/MubinAdmin
// +----------------------------------------------------------------------

namespace app\common\traits;

use app\admin\model\Menu;
use app\common\facade\UserInfo;
use think\facade\View;
use app\middleware\admin\{LoginCheck};
use think\{Container,Exception};

trait Admin
{
    use Entrust;

    // 定义控制器中间件
    protected $middleware = [
        LoginCheck::Class,
    ];

    protected $view;

    /**
     * 初始化模板
     * @param array $param 替换字符参数
     * @return mixed
     * @author staitc7 <static7@qq.com>
     */
    protected function initView(?array $param = [])
    {
        $viewReplace = $this->app->config->get('app.template',[]);
        View::config(array_merge($viewReplace, $param));
        return $this;
    }

    /**
     * 设置视图并输出
     * @param array  $value 赋值
     * @param string $template 模板名称
     * @param bool   $menus 菜单
     * @return mixed
     * @throws \Exception
     * @author staitc7 <static7@qq.com>
     */
    protected function setView(?array $value = [], ?string $template = '', $menus = true)
    {
        //检测模板初始化
        $this->initView();
        return View::fetch($template ?: '',$value ?: []);
    }
}